package main

import (
	"context"
	"fmt"
)

func main() {
	parent := context.Background()
	ctx, cancel := context.WithCancel(parent)
	runTimes := 0
	go func(ctx context.Context, count int) {
		for {
			select {
			case <-ctx.Done():
				fmt.Println("Goroutine Done")
				return
			default:
				fmt.Printf("Goroutine Running Times: %d\n", runTimes)
				runTimes++
			}
			if runTimes == count {
				cancel()
			}
		}
	}(ctx, 5)
	for done:=<-ctx.Done();done != struct{}{};done=<-ctx.Done(){}
}
